(function(){
	angular.module('app').component('industrySelectComponent',{
		templateUrl:'app/components/industry.select.component/industry.select.component.html',
		controller: industrySelectComponent,
		controllerAs:'vm'
	});

	industrySelectComponent.$inject = ['$scope','$rootScope','industrySelectComponentService','$window','atomicNotifyService'];

	function industrySelectComponent($scope,$rootScope,service,$window,atomicNotifyService){
		var vm = this;

		vm.industry = {
			menu:[],
			curMenu:'',
			subMenu:[],
			curSubMenu:'',
			submit:_submit
		}

		$('#industry-select-modal').modal();

		var clearFun = $rootScope.$on('industry_select_EV',function(){
			

			$('#industry-select-modal').modal('open');

			service.getIndustry().then(function(data){
				// console.log(data);

				vm.industry.menu = data;

			},function(err){});

		});

		$scope.$watch('vm.industry.curMenu',function(newValue,oldValue){
			if(angular.equals(newValue, oldValue)){
				return;
			}
			vm.industry.curSubMenu = '';
			service.getSub(vm.industry.curMenu).then(function(data){

				vm.industry.subMenu = data;

			},function(err){});

		});


		function _submit(){

			if(vm.industry.curSubMenu =='' || vm.industry.curMenu ==''){
				atomicNotifyService.info('请选择行业和类目');
				return;
			}
			var data = vm.industry.curMenu+'--'+vm.industry.curSubMenu;
			service.submit(data).then(function(resp){

				$window.location.reload();

			},function(err){
				atomicNotifyService.info(err.message);
			});


		}


	}
})();